#ifndef __HB__LIST
#define __HB__LIST

#include <type.h>

struct list_head{
    struct list_head *next, *prev;
};

#define POISION_POINTER_DELTA 0xdead000000000000
#define LIST_POISON1  ((void *) 0x00100100 + POISION_POINTER_DELTA)
#define LIST_POISON2  ((void *) 0x00200200 + POISION_POINTER_DELTA)

static inline void INIT_LIST_HEAD(struct list_head *list){
    list->next = list;
    list->prev = list;

}


static inline void __list_add(struct list_head *newNode, struct list_head *prev,
        struct list_head *next)
{
    next -> prev = newNode;
    newNode -> next = next;
    newNode -> prev = prev;
    prev ->next = newNode;
}

static inline void list_add(struct list_head *newNode, struct list_head *node)
{
    __list_add(newNode, node, node->next);
}

static inline void list_add_tail(struct list_head *newNode, struct list_head *node){
    __list_add(newNode, node->prev, node);
}

static inline void __list_del(struct list_head *prev, struct list_head *next){
    next->prev = prev;
    prev->next = next;
}

static inline void list_del(struct list_head *node){
    __list_del(node->prev, node->next);
    node->next = LIST_POISON1;
    node->next = LIST_POISON2;
}

static inline int list_empty(struct list_head *node){
    return node->next == node;
}

#endif // !_HB_LIST
